<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
var average = function(salary) {
    salary.sort((a,b) => (a-b))
    salary.pop()
    salary.shift()
    let sum = 0
    for( var i = 0 ; i<salary.length ; i++ ){
        sum = sum + salary[i]
    }
    return sum/salary.length
};

var salary = [4000,3000,1000,2000]
console.log(average(salary))
    </script>
</body>
</html>